package com.example.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class InternalPage extends AnyPage {

	@FindBy(xpath = "//nav//li[1]/a")
	public WebElement menuHomeLink;

	@FindBy(xpath = "//nav//li[2]/a")
	public WebElement menuProfileLink;

	@FindBy(xpath = "//nav//li[3]/a")
	public WebElement menuUserManagementLink;

	@FindBy(xpath = "//nav//li[4]/a")
	public WebElement menuLogoutLink;

	@FindBy(className = "error")
	public WebElement error;

	@FindBy(className = "content")
	public WebElement content;

	public boolean isOnThisPage() {
		return menuLogoutLink.isDisplayed();
	}

	public LoginPage logOut() {
		menuLogoutLink.click();
		waits().until(alertIsPresent()).accept();
		return MyPageFactory.getPage(driver, LoginPage.class);
	}

	public UserPage goToUserManagement() {
		menuUserManagementLink.click();
		return MyPageFactory.getPage(driver, UserPage.class);
	}

	@Override
	public void tryToOpen() {
		MyPageFactory.getPage(driver, LoginPage.class)
				.logInwithValidCredentials(login, oldPass);
	}
}